var text = [{
  title: '项目评价', ph: '文字评价（选填）', btn: '提交', succ: '评价成功', load: '评分中'
}, {
  title: '项目评价', ph: '文字评价（选填）', btn: '提交', succ: '评价成功', load: '评分中'
}], 
question = [
  [       // 发布者评分的内容
    [
      { id:0, q:'项目难度' }, { id:1, q:'完成情况' }, { id:2, q:'合作态度' }
    ], [
      { id:0, q:'项目难度' }, { id:1, q:'完成情况' }, { id:2, q:'合作态度' }
    ]
  ], [    // 完成者评分的内容
    [
      { id:0, q:'项目难度' }, { id:1, q:'奖励情况' }, { id:2, q:'合作态度' }
    ], [
      { id:0, q:'项目难度' }, { id:1, q:'奖励情况' }, { id:2, q:'合作态度' }
    ]
  ]
],
marks = [
  [     // 发布者评分的分数
    [
      { id: 0, n: 0 }, { id: 1, n: 0 }, { id: 2, n: 0 }
    ], [
      { id: 0, n: 0 }, { id: 1, n: 0 }, { id: 2, n: 0 }
    ]
  ], [     // 完成者评分的分数
    [
      { id: 0, n: 0 }, { id: 1, n: 0 }, { id: 2, n: 0 }
    ], [
      { id: 0, n: 0 }, { id: 1, n: 0 }, { id: 2, n: 0 }
    ]
  ]
],
form = { idPractice: null };

// 任务发布者评分，id 为 0； 任务接收者评分，id 为 1
Page({
  data: {
   PUBLISHER: true,
   btnClr: '#ffeec6',
   textClr: '#aaa',
  },

  onLoad(option) {
    form.idPractice = option.idPractice;
    let identity = 1;
    if (option.evaluate == '0') {
      this.setData({ PUBLISHER: false });
      identity = 0;
    }
    this.setData({
      question: question[identity][wx.lang],
      text: text[wx.lang],
      today: wx.formatTime(new Date(), '-'),
    })
  },
  onShow() {
    let title = text[wx.lang].title;
    wx.onShow(this, title, wx.theme);
    let clr = wx.rgb(wx.theme)
    this.setData({ btnArea: clr.join(',')  })
    let obj = ['show1', 'show2', 'show3', 'show4', 'show5', 'show6'];
    wx._slide_v(this, obj, wx.system.height, 0, () => {
      wx.slide_v(this, obj, 0, 1, .5, () => {
        this.setData({ showText: 1 });
      });
    })
  }, 

  input(e) {
    form.c = e.detail.value;
  },

  // returns whether the button is available 
  lightUp() {
    let identity = this.data.PUBLISHER ? 1 : 0;
    for (let i = 0; i < marks[identity][wx.lang].length; ++i) {
      if (marks[identity][wx.lang][i].n == 0) {
        this.setData({ textClr: '#aaa', btnClr: '#ffeec6' });
        console.log(marks[identity][wx.lang][i]);
        return false;
      }
    }
    this.setData({ textClr: '#fff', btnClr: '#f4d66d' });
    return true;
  },

  // 发送提交请求
  upload(formid) {
    if (this.data.PUBLISHER) {
      form.publisher = {};
      form.publisher.m = marks[1][wx.lang];  // m 为评分
      if (form.c) form.publisher.c = form.c; // c 为文字
    } else {
      form.receiver = {};
      form.receiver.m = marks[1][wx.lang];  // m 为评分
      if (form.c) form.receiver.c = form.c; // c 为文字
    } 
    console.log(form)
    wx.post('Evaluate.submitEvaluation', form, res => {
      wx.toast(text[wx.lang].succ, 1);
      wx.appData.refreshTab = 1;
      setTimeout(() => {
        wx.navigateBack({
          delta: 1,
        });
      }, 2000);
    }, text[wx.lang].load);
  },

  starChange(e) {
    let id = e.currentTarget.id;
    if (this.data.PUBLISHER) marks[1][wx.lang][id].n = e.detail * 2;
    else marks[0][wx.lang][id].n = e.detail * 2;
    this.lightUp();
  }
})